package com.woniu.mapper;

import com.woniu.entity.Product;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
* @author 11370
* @description 针对表【product】的数据库操作Mapper
* @createDate 2025-06-24 17:26:45
* @Entity com.woniu.entity.Product
*/
public interface ProductMapper {
    @Select("select * from product")
    public List<Product> selectProduct();

    @Select("select * from product where pid=#{pid}")
    public Product selectProductById(int pid);

    @Update("update product set stock=stock-#{stock} where pid=#{pid}")
    public void updateProductStock(@Param("pid") Integer pid, @Param("stock") int stock);

    @Select("select * from product where merchant_id=#{merchant_id}")
    public List<Product> selectProductByUid(int merchant_id);

    @Insert("insert into product(pname,price,stock,des,createdtime,updatetime,merchant_id) values (#{pname},#{price},#{stock},#{des},#{createdtime},#{updatetime},#{merchant_id})")
    public void insertProduct(Product product);

    @Update("update product set price=#{price} where pid=#{pid}")
    public void updateProductPrice(@Param("pid") Integer pid, @Param("price") double price);

    @Delete("delete from product where pid=#{pid}")
    public void deleteProduct(int pid);

    @Delete("delete from product where merchant_id=#{merchant_id}")
    public void deleteProductByMerchantId(int merchant_id);

    @Select("select * from product where pname like concat('%', #{pname}, '%') ")
    public List<Product> selectProductByName(String pname);

    @Select("select * from product where pname like concat('%', #{pname}, '%') and merchant_id=#{merchant_id}")
    public Product selectProductMidName(@Param("merchant_id") Integer merchant_id,@Param("pname") String pname);
}




